package l1j.server.server.datatables.lock;

import java.util.HashMap;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import l1j.server.server.datatables.sql.HellTimeTable;
import l1j.server.server.datatables.storage.HellTimeStorage;
import l1j.server.server.templates.L1HellTime;

public class HellTimeReading {
	private final Lock _lock;

	private final HellTimeStorage _storage;

	private static HellTimeReading _instance;

	private HellTimeReading() {
		this._lock = new ReentrantLock(true);
		this._storage = new HellTimeTable();
	}

	public static HellTimeReading get() {
		if (_instance == null) {
			_instance = new HellTimeReading();
		}
		return _instance;
	}
	
	/**
	 * 初始化載入
	 */
	public void load() {
		this._lock.lock();
		try {
			this._storage.load();
			
		} finally {
			this._lock.unlock();
		}
	}
	
	public HashMap<Integer, L1HellTime> getObjidList() {
		this._lock.lock();
		try {
		return this._storage.getObjidList();
		} finally {
			this._lock.unlock();
		}
	}
	
	public L1HellTime getTempByObjid(final int objid) {
		this._lock.lock();
		try {
			return this._storage.getTempByObjid(objid);
		} finally {
			this._lock.unlock();
		}
	}

	public void BeginHell(final int objid , final int helltime) {
		this._lock.lock();
		try {
			this._storage.BeginHell(objid, helltime);
		} finally {
			this._lock.unlock();
		}
	}

	public void EndHell(final int objid) {
		this._lock.lock();
		try {
			this._storage.EndHell(objid);
		} finally {
			this._lock.unlock();
		}
	}

	public Set<Integer> getOrderSet() {
		this._lock.lock();
		try {
		return this._storage.getOrderSet();
		} finally {
			this._lock.unlock();
		}
	}
}
